#include "MoveState.h"
#include "View.h"
#include "Editor.h"

namespace FinalRendering
{
	namespace Editor
	{
		MoveState::MoveState(View * view, int x, int y, bool _autoPop)
		{
			capturedView = view;
			lstX = x;
			lstY = y;
			autoPop = _autoPop;
		}

		void MoveState::MouseDown(View * view, UIMouseEventArgs & e)
		{
			capturedView = view;
			lstX = e.X; lstY = e.Y;
		}

		void MoveState::MouseUp(View * view, UIMouseEventArgs & e)
		{
			capturedView = 0;
			if (autoPop)
				WorldEditor->PopState();
		}


		void MoveState::MouseMove(View * view, UIMouseEventArgs & e)
		{
			if (view != capturedView)
				return;
			view->Move(e.X-lstX, e.Y-lstY);
			lstX = e.X;
			lstY = e.Y;
			view->Refresh();
		}
	}
}